home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 416_01 / matrix / matrix.doc < prev    next >
Text File  |  1990-07-11  |  3KB  |  162 lines

  1. MATRIX FUNCTIONS
  2. ----------------
  3. Written by Nigel Salt for Microsoft C V5.1
  4.  
  5. The 3D graphics library requires a VGA display 
  6. You could convert the routines for other displays
  7. but then you would have to include aspect ratio calculations
  8. The VGA has a perfect aspect ratio
  9.  
  10. There is a book on computer graphics which is dated and based on the
  11. Spectrum computer but nevertheless very good
  12. Advanced Graphics with teh Sinclair ZX Spectrum
  13. I.O.Angell & B.J.Jones
  14. Published Macmillan Press
  15. ISBN 0 333 35050
  16.  
  17. Below are descriptions of the matrix and 3d geometry functions in
  18. this library of routines
  19.  
  20. MATRIX FUNCTIONS
  21.  
  22. /* Matrix structure */
  23. typedef struct
  24. {
  25.   int rows;
  26.   int cols;
  27.   double *block;
  28. } matrix,*matrixptr;
  29.  
  30. /*   E.G. of Matrix declaration for a 4 x 4 matrix
  31. double b4x4A[4][4]=
  32. {
  33.   6,1,6,6,
  34.   1,6,6,0,
  35.   0,3,2,1,
  36.   8,6,1,9
  37. };
  38. matrix m4x4A={4,4,&b4x4A[0][0]};
  39. */
  40.  
  41. /* Function prototypes */
  42. void mprint(matrixptr);
  43.     Print out a matrix to stdout
  44.  
  45. void smmult(matrixptr,double);
  46.     Scalar multiply a matrix by a value
  47.  
  48. int madd(matrixptr m1,matrixptr m2,matrixptr dm);
  49.     Add matrix m1 to m2 giving dm
  50.  
  51. int mmult(matrixptr m1,matrixptr m2,matrixptr dm);
  52.     Multiply matrix m1 by m2 giving dm
  53.  
  54. int mcopy(matrixptr sm,matrixptr dm);
  55.     Copy matrix sm to dm
  56.  
  57. int mtrans(matrixptr sm,matrixptr dm);
  58.     Transpose matrix sm and put result in dm
  59.  
  60. double det(matrixptr m);
  61.     Find determinant of matrix m
  62.  
  63. int minv(matrixptr sm,matrixptr dm);
  64.     Invert matrix sm and put result in dm
  65.  
  66. int nsolve(int rows,double *data);
  67.     Solve equation in N unknowns
  68.  
  69. int mid(matrixptr);
  70.     Set matrix to the identity matrix
  71.     EG 100
  72.        010
  73.        001
  74.  
  75. void mzero(matrixptr);
  76.     Set all cells of matrix to Zero
  77.  
  78. 3D FUNCTIONS
  79.  
  80. An object is defined as below
  81.  
  82. typedef struct
  83. {
  84. int points;
  85. int lines;
  86. double *pdat;
  87. int  *ldat;
  88. } object,*objectptr;
  89.  
  90. As an example a cube would be defined as follows
  91.  
  92. double cubep[8][3]=
  93. {
  94.   1,1,1,
  95.   1,1,-1,
  96.   1,-1,-1,
  97.   1,-1,1,            Each row is an x,y,z coordinate
  98.   -1,1,1,
  99.   -1,1,-1,
  100.   -1,-1,-1,
  101.   -1,-1,1
  102. };
  103.  
  104. int cubel[12][2]=
  105. {
  106.   0,1,               Each pair is a line between two of the cubep
  107.   1,2,               points
  108.   2,3,
  109.   3,0,
  110.   4,5,
  111.   5,6,
  112.   6,7,
  113.   7,4,
  114.   0,4,
  115.   1,5,
  116.   2,6,
  117.   3,7
  118. };
  119.  
  120. Finally the object definition says that the cube object has 8 points
  121. and 12 lines joining them and gives the address of the data blocks
  122. for the lines and points
  123.  
  124. object cube=
  125. {
  126.   8.0,12.0,&cubep[0][0],&cubel[0][0]
  127. };
  128.  
  129.  
  130. /* function prototypes */
  131. int tran3(matrixptr m,double tx,double ty,double tz);
  132.   Translate matrix m by tx ty tz
  133.  
  134. int scale3(matrixptr m,double sx,double sy,double sz);
  135.   Scale matrix m by sx sy sz
  136.  
  137. int rot3(matrixptr m,double theta,int axis);
  138.     Rotate matrix m by theta radians about axis
  139.     (1=x,2=y,3=z)
  140.     
  141. double angle(double ax,double ay);
  142.     Return arctangent of ax/ay in radians
  143.  
  144. void p3mult(double *,matrixptr);
  145.     Multiply a point by a matrix
  146.  
  147. int objcop(objectptr s,objectptr d);
  148.     Copy object pointed to by s to destination pointed to by d
  149.  
  150. int init3d(void);
  151.     Set VGA graphics mode etc
  152.  
  153. void objtran(objectptr o,matrixptr m);
  154.     translate an object by matrix m
  155.  
  156. void objprin(objectptr o);
  157.     print out an object definition
  158.  
  159. void objdraw(objectptr o);
  160.     draw the object on the screen
  161.  
  162.